<template>
  <div>
    <div class="head">
      <text>随心享</text>
      <button
        style="float: right; display: flex; margin-top: -30px; font-size: 20px"
        @click="outlogin"
      >
        退出
      </button>
    </div>
    <div>
      <el-row class="tac">
        <el-col :span="4">
          <h5 class="mb-2" style="font-size: 20px">菜单栏</h5>
          <el-menu active-text-color="#ffd04b" default-active="1">
            <el-menu-item index="1" @click="general">
              <el-icon><icon-menu /></el-icon>
              <span style="font-size: 17px">动态审核</span>
            </el-menu-item>
            <el-menu-item index="2" @click="report">
              <el-icon><setting /></el-icon>
              <span style="font-size: 17px">评论审核</span>
            </el-menu-item>
          </el-menu>
        </el-col>
        <el-col :span="20">
          <h5 class="mb-2" style="font-size: 20px">数据</h5>
          <div v-if="IsGeneral">
            <el-table :data="tableData.value">
              <el-table-column prop="dExamineId" label="审核ID" />
              <el-table-column prop="badUserId" label="用户ID" />
              <el-table-column prop="badUser" label="用户名" />
              <el-table-column prop="dynamicId" label="动态ID" />
              <el-table-column label="Operations">
                <template #default="scope">
                  <el-button
                    size="small"
                    id="button1"
                    type="success"
                    @click="common(scope.row)"
                    >普通</el-button
                  >
                  <el-button
                    size="small"
                    id="button2"
                    type="warning"
                    @click="warning(scope.row)"
                    >警告</el-button
                  >
                  <el-button
                    size="small"
                    id="button3"
                    type="danger"
                    @click="fenghao(scope.row)"
                    >封号</el-button
                  >
                  <el-button
                    size="small"
                    id="button7"
                    type="info"
                    @click="detail(scope.row)"
                    >详情</el-button
                  >
                  <adminitorOperations></adminitorOperations>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination small layout="prev, pager, next" :total="90" />
          </div>
          <div v-if="!IsGeneral">
            <el-table :data="tableData1.value">
              <el-table-column prop="examineId" label="审核ID" />
              <el-table-column prop="reviewId" label="评论ID" />
              <el-table-column prop="content" label="评论内容" />
              <el-table-column prop="baduUerId" label="用户ID" />
              <el-table-column prop="badUser" label="用户名" />
              <el-table-column label="Operations">
                <template #default="scope">
                  <el-button
                    size="small"
                    type="success"
                    id="button4"
                    @click="common1(scope.row)"
                    >普通</el-button
                  >
                  <el-button
                    size="small"
                    type="warning"
                    @click="warning1(scope.row)"
                    id="button5"
                    >警告</el-button
                  >
                  <el-button
                    size="small"
                    type="danger"
                    id="button6"
                    @click="fenghao1(scope.row)"
                    >封号</el-button
                  >
                  <adminitorOperations></adminitorOperations>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination small layout="prev, pager, next" :total="90" />
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { Menu as IconMenu, Setting } from '@element-plus/icons-vue'
import { ref } from '@vue/reactivity'
import { useRouter } from 'vue-router'
import axios from 'axios'
import { onMounted, reactive } from 'vue'
onMounted(() => {
  dExamineshow()
  dxamineshow()
})

const IsGeneral = ref(true)
const tableData = reactive([])
const tableData1 = reactive([])

const router = useRouter()

function general() {
  IsGeneral.value = true
}
function report() {
  IsGeneral.value = false
}

function outlogin() {
  router.push('/login')
}

function detail(row) {
  router.push('/adminDetail?dynamicId=' + row.dynamicId)
}
function common(row) {
  juRequest(
    row.dExamineId,
    document.getElementById('button1').innerText,
    row.badUserId,
    row.dynamicId
  )
}

function warning(row) {
  juRequest(
    row.dExamineId,
    document.getElementById('button2').innerText,
    row.badUserId,
    row.dynamicId
  )
}

function fenghao(row) {
  juRequest(
    row.dExamineId,
    document.getElementById('button3').innerText,
    row.badUserId,
    row.dynamicId
  )
}

function common1(row) {
  comRequest(
    row.examineId,
    document.getElementById('button4').innerText,
    row.baduUerId
  )
}

function warning1(row) {
  comRequest(
    row.examineId,
    document.getElementById('button5').innerText,
    row.baduUerId
  )
}

function fenghao1(row) {
  comRequest(
    row.examineId,
    document.getElementById('button6').innerText,
    row.baduUerId
  )
}

function juRequest(dExamineId, result, badUserId, dynamicId) {
  axios({
    url: 'http://localhost:8080/dExamine/examine',
    method: 'post',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    },
    data: {
      dExamineId: dExamineId,
      result: result,
      badUserId: badUserId,
      dynamicId: dynamicId
    }
  }).then(function (response) {
    alert(response.data.result)
  })
}

function comRequest(examineId, results, baduUerId) {
  axios({
    url: 'http://localhost:8080/examine/AdminSelectExamine',
    method: 'post',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    },

    data: {
      examineId: examineId,
      results: results,
      badUserId: baduUerId
    }
  }).then(function (response) {
    alert(response.data.result)
  })
}
function dExamineshow() {
  axios({
    url: 'http://localhost:8080/dExamine/showAll',
    method: 'get',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    }
  }).then(function (response) {
    console.log(response.data)
    tableData.value = response.data.data
    console.log(tableData.value)
  })
}
function dxamineshow() {
  axios({
    url: 'http://localhost:8080/examine/AdminShowExamine',
    method: 'post',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    }
  }).then(function (response) {
    console.log(response.data)
    tableData1.value = response.data.data
    console.log(tableData1.value)
  })
}
</script>

<style lang="scss">
.head {
  height: 100px;
  width: 100%;
  background-color: rgb(167, 221, 253);
  padding-top: 30px;
  font-size: 40px;
}
</style>
